layui.define(['constants', '_'],function(exports) {
    var constants = layui.constants,
        _ = layui._;
    function Filters() {
	    /**
	     * @author: ares
	     * @date: 2020/5/24 16:32
	     * @description: 常量舒配
	     * @param {array}constant
	     * @param {string}valueMark
	     * @returns {Function}
	     */
	    this.constantFilter = function(constant, valueMark) {
	    	var valueMark = valueMark || 'v';
		    return function (value) {
			    const temp = constant;
			    const filter = _.filter(temp, function(item) {
				    return item.k == value
			    });
			    return filter[0] && filter[0][valueMark] || '';
		    }
	    }
    }

    Filters.prototype = {
        constructor: Filters,
        /**
         * @author: ares
         * @date: 2018/12/6 14:45
         * @description: 根据时间戳转化为年龄
         * @param {number}value   时间戳
         * @returns {*}
         */
        ageFormat: function(value) {
            if (!value) return '';
            var incomingDate = new Date(value),
                currentDate = new Date(),
                oldYear = incomingDate.getFullYear(),
                oldMonth = incomingDate.getMonth(),
                oldDay = incomingDate.getDate(),
                nowYear = currentDate.getFullYear(),
                nowMonth = currentDate.getMonth(),
                nowDay = incomingDate.getDate();
            if (nowYear > oldYear) {
                return nowYear - oldYear + "岁";
            } else if (nowYear == oldYear && nowMonth > oldMonth) {
                return nowMonth - oldMonth + "月";
            } else if (nowYear == oldYear && nowMonth == oldMonth) {
                return "不足月";
            } else {
                return '';
            }
        },

        /**
         * @author: ares
         * @date: 2018/8/21 14:26
         * @description: 性别代码转化为性别
         * @param {string}value  性别代码
         * @returns {string}
         */
        sexFormat: function(value) {
            if (value == null) return '';
            var sexFilter = {
            	'0': '女',
            	'women': '女',
            	'female': '女',
            	'1': '男',
            	'man': '男',
            	'male': '男',
            };
            return sexFilter[value] || '未知';
        },
    }

	exports('filters',new Filters());
})